#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/9/27 18:14
# @Author  : 朱宽
# @File    : simulateMouse.py
# @Software: Win10、Python3.8.5 and Pycharm
'''
模拟鼠标操作
'''
from selenium.webdriver.common.action_chains import ActionChains


class simulateMouse():
    '''
    定义了：
    1、点击一下鼠标左键
    2、点击两下鼠标左键
    3、点击一下鼠标右键
    4、移动鼠标至element上
    5、从source移动鼠标到target
    6、按住source，并拖拽source到target
    7、拖拽元素到坐标(x,y)
    8、按住元素且不释放
    '''

    def __init__(self, driver):
        self.driver = driver
        self.actions = ActionChains(self.driver)

    def left_click(self, element):
        '''
        1、点击一下鼠标左键
        :param element:
        :return:
        '''
        self.actions.click(element).perform()

    def double_left_click(self, element):
        '''
        2、点击两下鼠标左键
        :param element:
        :return:
        '''
        self.actions.double_click(element).perform()

    def right_click(self, element):
        '''
        3、点击一下鼠标右键
        :param element:
        :return:
        '''
        self.actions.context_click(element).perform()

    def move_mouse(self, element):
        '''
        4、移动鼠标至element上
        :param element:
        :return:
        '''
        self.actions.move_to_element(element).perform()

    def move_mouse_source_target(self, source, target):
        '''
        5、从source移动鼠标到target
        :param source:
        :param target:
        :return:
        '''
        self.actions.drag_and_drop(source, target).perform()

    def move_source_target(self, source, target):
        '''
        6、按住source，并拖拽source到target
        :param source:
        :param target:
        :return:
        '''
        self.actions.click_and_hold(source).release(target).perform()

    def drag_element(self, element, x, y):
        '''
        7、拖拽元素到坐标(x,y)
        :param element:
        :param x:
        :param y:
        :return:
        '''
        self.actions.click_and_hold(element).move_by_offset(x, y).release().perform()

    def click_hold(self, element):
        '''
        8、按住元素且不释放
        :param element:
        :return:
        '''
        self.actions.click_and_hold(element)


if __name__ == '__main__':
    pass